package artid.com.arttogo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import java.util.ArrayList;

import artid.com.arttogo.R;
import artid.com.arttogo.adapter.LotDetFragmentAdapter;
import artid.com.arttogo.bean.ShareItem;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.utils.Config;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.SubViewPager;

//拍品详情承载页
public class LotDetailPagerActivity extends BaseActivity implements OnClickListener {

	public static SubViewPager mViewPager;
	LotDetFragmentAdapter adapter;
	ImageView ivShare;
	ShareItem shareitem;
	public static Boolean isCreat = true;
//	public static TextView mTittle;
//	public static List<ShareItem> listshare = new ArrayList<ShareItem>();
	private String id="";//艺术品ID
	private String imgwide;//请求的图片宽度
	private String messid="";//消息ID
	ArrayList<String> arrayids;
	private String titileName;//标题名称
	
	
	@Override
	protected void onResume() {
		super.onResume();
		isCreat = true;
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = LotDetailPagerActivity.this;
		imgwide=(Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)))+"";
		setContentView(R.layout.activity_collectdet_pager);
		mViewPager = (SubViewPager)findViewById(R.id.viewPager);
		mBack = (ImageView)findViewById(R.id.back_btn);
		mBack.setOnClickListener(this);
		ivShare = (ImageView)findViewById(R.id.share_collection_detail);
		ivShare.setVisibility(View.VISIBLE);
		ivShare.setOnClickListener(this);
		titileName = getIntent().getExtras().getString("titleName");
		adapter = new LotDetFragmentAdapter(getSupportFragmentManager(),titileName);
		id = getIntent().getExtras().getString("id");
		if (!TextUtils.isEmpty(id)) {
			arrayids = new ArrayList<String>();
			arrayids.add(id);
		}else {
			 arrayids = getIntent().getExtras().getStringArrayList("id");
		}
		
		//判断是否来自机构
		Boolean isFromOrg = getIntent().getExtras().getBoolean("isOrg");
		if (isFromOrg==null) {
			isFromOrg = false;
		}

		if (isFromOrg) {
			adapter.setCodeMode(isFromOrg);
			adapter.setInsData(arrayids);
		}else{
			adapter.setData(arrayids);
			adapter.notifyDataSetChanged();
		}
		index = 0;
		index = getIntent().getExtras().getInt("index");
		mViewPager.setAdapter(adapter);
		mViewPager.setOffscreenPageLimit(1);
		mViewPager.setOnPageChangeListener(mOnPageChangeListener);
		mViewPager.setCurrentItem(index);
//		getData();
	}
	
	public static int index = 0;
	private OnPageChangeListener mOnPageChangeListener = new OnPageChangeListener() {
		@Override
		public void onPageSelected(int position) {
			index = position;
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {

		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
			
		}
	};

	protected void onDestroy() {
		super.onDestroy();

	};
	
	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.back_btn:
			finish();
			break;
		case R.id.share_collection_detail:

			if (shareitem == null) {
				Config.showTip(LotDetailPagerActivity.this, "请检查网络连接");
			}
			AppUtil.shareWithTalk(mContext, shareitem.getTitle(), shareitem.getContent(), shareitem.getImageUrl(), shareitem.getUrl(), shareitem.getUid(), shareitem.getHeadUrl(),shareitem.getAname());
			break;
		default:
			break;
		}
	}

}
